package com.vessel.decoration.mvp.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.vessel.decoration.BuildConfig;
import com.vessel.decoration.R;
import com.vessel.decoration.app.base.MySupportAdapter;
import com.vessel.decoration.app.data.entity.ArtisanInfoResponse;
import com.vessel.decoration.app.utils.UiHelper;

public class WorkerSkillAdapter extends MySupportAdapter<ArtisanInfoResponse.SkillsBean> {

    private AppComponent mAppComponent;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_me_skill, null);
            viewHolder.chaptersPic = UiHelper.find(convertView, R.id.worker_item_pic);
            viewHolder.name = UiHelper.find(convertView, R.id.worker_item_name);
            viewHolder.remark = UiHelper.find(convertView, R.id.worker_item_remark);
            viewHolder.price = UiHelper.find(convertView, R.id.worker_item_price);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ArtisanInfoResponse.SkillsBean info = getItem(position);
        Glide.with(parent.getContext()).load(BuildConfig.APP_DOMAIN + info.getSkillPic()).into(viewHolder.chaptersPic);
        viewHolder.name.setText(info.getSkillName());
        viewHolder.remark.setText(info.getRemark());
        viewHolder.price.setText("¥" + info.getPrice() + "元");
        if (mAppComponent == null) {
            mAppComponent = ArmsUtils.obtainAppComponentFromContext(convertView.getContext());
        }
        mAppComponent.imageLoader()
                .loadImage(convertView.getContext(), ImageConfigImpl
                        .builder()
                        .imageView(viewHolder.chaptersPic)
                        .url(BuildConfig.APP_DOMAIN + info.getSkillPic())
                        .build());
        return convertView;
    }

    class ViewHolder {
        ImageView chaptersPic;
        TextView name;
        TextView remark;
        TextView price;
    }
}
